package cc.admin.modules.wea.service.impl;

import cc.admin.modules.wea.entity.WeaApi;
import cc.admin.modules.wea.entity.WeatherConstant;
import cc.admin.modules.wea.mapper.WeaApiMapper;
import cc.admin.modules.wea.service.IWeaApiService;
import cc.admin.modules.wea.utils.WeatherUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

/**
 * @Description: 海洋天气api
 * @Author: cc-admin
 * @Date:   2024-09-10
 * @Version: V1.0.0
 */
@Service
public class WeaApiServiceImpl extends ServiceImpl<WeaApiMapper, WeaApi> implements IWeaApiService {

    @Autowired
    private IWeaApiService weaApiService;
    @Override
    public String getWeather(String token, String type, String location) {
        try {
            QueryWrapper queryWrapper=new QueryWrapper();
            queryWrapper.eq("token",token);
            List<WeaApi> tokenList=weaApiService.list(queryWrapper);
            for (WeatherConstant value : WeatherConstant.values()) {
                if (value.name().equals(type)) {
                    if(tokenList.size() > 0){
                        String weatherData = WeatherUtil.getWeather(value, location);
                        return weatherData;
                    }
            }

            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return null;
    }
}
